package binarytree

func constructMaximumBinaryTree(nums []int) *TreeNode {

	if len(nums) == 0 {
		return nil
	}

	maxIndex := 0

	for i, v := range nums {
		if v > nums[maxIndex] {
			maxIndex = i
		}
	}
	father := &TreeNode{
		Val:   nums[maxIndex],
		Left:  constructMaximumBinaryTree(nums[:maxIndex]),
		Right: constructMaximumBinaryTree(nums[maxIndex+1:]),
	}
	return father

}
